package com.legoo.studaychineseonline.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;


import com.legoo.studaychineseonline.base.BaseActivity;
import com.tencent.mm.opensdk.modelpay.PayReq;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;



import java.util.HashMap;
import java.util.Map;

/**

 */

public class WxPayActivity extends BaseActivity {
    private Context context;

    private IWXAPI iwxapi;
    private static final String APP_ID = "wx92e0418212179840";
    @Override
    protected void myOnCreate(@Nullable Bundle savedInstanceState) {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void resolveBundle(Bundle bundle) {

    }

    @Override
    protected int myLayoutId() {
        return 0;
    }

    public WxPayActivity() {
    }

    public WxPayActivity(Context context) {
        this.context = context;
    }

    public void wxPay(String money, String goods_id) {

//        showProgressDialog();

        iwxapi = WXAPIFactory.createWXAPI(context, APP_ID, true);

        //将应用的api注册到微信
        iwxapi.registerApp(APP_ID);

        Map<String, Object> map = new HashMap<>();
        map.put("type", "wechat");
        map.put("price", money);
        map.put("uid", goods_id);
//        XUtil.Post(API.RECHARGE, map, new Callback.CommonCallback<String>() {
//            @Override
//            public void onSuccess(String result) {
//
//                WxPayBean wxPayBean = new Gson().fromJson(result,WxPayBean.class);
//
//
//                PayReq req = new PayReq();
//                req.appId = wxPayBean.getData().getAppid();
//                  req.partnerId =wxPayBean.getData().getMch_id();
//                req.prepayId = wxPayBean.getData().getPrepayid();
//                req.nonceStr = wxPayBean.getData().getNonceStr();
//                req.timeStamp = wxPayBean.getData().getTimeStamp()+"";
//                req.packageValue = wxPayBean.getData().getPackageX();
//                req.sign = wxPayBean.getData().getSign();
//                req.extData = "app data"; // optional
//              Log.e("shuxi"," req.appId = "+ req.appId+" ,req.partnerId =" +req.partnerId+
//              " ,req.prepayId= "+  req.prepayId+"  ,req.nonceStr ="+  req.nonceStr+",req.timeStamp ="+req.timeStamp+
//                   ", req.packageValue = "+ req.packageValue+",  req.sign = "+  req.sign
//              );
//                iwxapi.sendReq(req);
//
//
//                //                hideProgressDialog();
//
//            }
//
//            @Override
//            public void onError(Throwable ex, boolean isOnCallback) {
//
//                Log.e("fail", ex.getMessage());
//
////                hideProgressDialog();
//            }
//
//            @Override
//            public void onCancelled(CancelledException cex) {
//
//            }
//
//            @Override
//            public void onFinished() {
//
//            }
//        });


    }

}
